from django_redis import get_redis_connection


def transfer(results, request):
    user = request.user
    user_id = str(user.id).encode()

    redis_con = get_redis_connection('default')
    for spit in results:
        spit_id = spit.get('id')
        thumbup_user_id_set = redis_con.smembers('thumbup_%s' % spit_id)
        collected_user_id_set = redis_con.smembers('collected_%s' % spit_id)
        if user_id not in thumbup_user_id_set:
            spit['hasthumbup'] = False
        else:
            spit['hasthumbup'] = True

        if user_id not in collected_user_id_set:
            spit['collected'] = False
        else:
            spit['collected'] = True

    return results
